package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.DateTimeUtils;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.enums.MessageTypeEnum;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;

/**
 * 消息通知表
 */
@Entity
@Table(name = "message")
public class Message extends SuperClassEntity<Message> {
    /**
     * 消息通知标题
     */
    private String title;
    /**
     * 消息内容
     */
    @Column(length = 500)
    private String content;
    /**
     * 发送给人员
     */
    @ManyToOne
    @JoinColumn(name = "send_to_user_id")
    private SystemUser sendToUser;
    /**
     * 消息类型
     */
    @Enumerated(value = EnumType.STRING)
    @Column(name = "message_type")
    private MessageTypeEnum messageTypeEnum;
    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;
    /**
     * 消息是否已读 0未读 1已读
     */
    @Column(columnDefinition = "bit default 0")
    private boolean readStatus;

    /**
     * 单号
     */
    private String code;

    /**
     * 备注
     */
    private String remark;

    /**
     * 关联设备type
     */
    private String deviceType;

    /**
     * token
     */
    private String deviceToken;


    public Message() {
    }

    public Message(String title, String content, SystemUser sendToUser, MessageTypeEnum messageTypeEnum, Enterprise enterprise,String code,String type,String token) {
        this.title = title;
        this.content = content;
        this.sendToUser = sendToUser;
        this.messageTypeEnum = messageTypeEnum;
        this.enterprise = enterprise;
        this.code = code;
        this.deviceType=type;
        this.deviceToken=token;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public MessageTypeEnum getMessageTypeEnum() {
        return messageTypeEnum;
    }

    public void setMessageTypeEnum(MessageTypeEnum messageTypeEnum) {
        this.messageTypeEnum = messageTypeEnum;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public boolean isReadStatus() {
        return readStatus;
    }

    public void setReadStatus(boolean readStatus) {
        this.readStatus = readStatus;
    }

    public SystemUser getSendToUser() {
        return sendToUser;
    }

    public void setSendToUser(SystemUser sendToUser) {
        this.sendToUser = sendToUser;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getDeviceType() {
        return deviceType;
    }

    public void setDeviceType(String deviceType) {
        this.deviceType = deviceType;
    }

    public String getDeviceToken() {
        return deviceToken;
    }

    public void setDeviceToken(String deviceToken) {
        this.deviceToken = deviceToken;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("messageType",StringConverters.null2String(getMessageTypeEnum().getName()));
        jsonObject.put("readStatus",StringConverters.null2Boolean(isReadStatus()));
        jsonObject.put("content",StringConverters.null2String(getContent()));
        jsonObject.put("code",StringConverters.null2String(getCode()));
        jsonObject.put("remark",StringConverters.null2String(getRemark()));
        jsonObject.put("deviceType",StringConverters.null2String(getDeviceType()));
        jsonObject.put("deviceToken",StringConverters.null2String(getDeviceToken()));
        return jsonObject;
    }
}
